Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
is-equal-shallow
Advanced tools
Does a shallow comparison of two objects, returning false if the keys or values differ.
The is-equal-shallow npm package is designed to perform shallow equality checks on objects or arrays. It is particularly useful when you need to quickly determine if two objects have the same top-level properties without deeply traversing their structures. This can be especially handy in optimizations where deep equality checks are too costly in terms of performance.
Shallow equality check for objects
This feature allows you to compare two objects to see if they have the same top-level properties and values. It's useful for checking if objects are 'equivalent' without considering nested properties.
{"const isEqualShallow = require('is-equal-shallow');\nconst obj1 = { a: 1, b: 2 };\nconst obj2 = { a: 1, b: 2 };\nconsole.log(isEqualShallow(obj1, obj2)); // true"}
Shallow equality check for arrays
Similar to objects, this feature enables shallow comparison of two arrays to determine if they contain the same elements in the same order, without going into nested arrays or objects.
{"const isEqualShallow = require('is-equal-shallow');\nconst arr1 = [1, 2, 3];\nconst arr2 = [1, 2, 3];\nconsole.log(isEqualShallow(arr1, arr2)); // true"}
Similar to is-equal-shallow, shallow-equal provides functionality for performing shallow equality checks. The main difference lies in the implementation details and the specific use cases each package might be optimized for. While is-equal-shallow focuses on a straightforward approach, shallow-equal might offer additional customization options or optimizations for specific scenarios.
shallowequal is another package that offers similar functionality to is-equal-shallow, allowing for shallow comparison of objects and arrays. The key difference might be in the API design or additional features such as custom comparator functions, which can provide more flexibility in how comparisons are performed.
Does a shallow comparison of two objects, returning false if the keys or values differ.
The purpose of this lib is to do the fastest comparison possible of two objects when the values will predictably be primitives.
false
is returned.Install with npm
$ npm i is-equal-shallow --save
var equals = require('is-equal-shallow');
equals(object_a, object_b);
Examples
equals({a: true, b: true}, {a: true, b: true});
//=> 'true'
equals({a: true, b: false}, {c: false, b: false});
//=> 'false'
equals({a: true, b: false}, {a: false, b: false});
//=> 'false'
Strict comparison for equality:
equals({a: true, b: true}, {a: true, b: 'true'});
//=> 'false'
When values are not primitives, false
is always returned:
equals({ b: {}}, { b: {}});
//=> 'false'
equals({ b: []}, { b: []});
//=> 'false'
Other object utils:
Object
constructor.Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on June 22, 2015.
FAQs
Does a shallow comparison of two objects, returning false if the keys or values differ.
We found that is-equal-shallow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.